package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbUserMapper;
import com.dongdongshop.pojo.TbUser;
import com.dongdongshop.pojo.TbUserExample;
import com.dongdongshop.service.UserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Service
@Component
public class UserServiceImpl implements UserService {
    @Resource
    private TbUserMapper userMapper;

    @Override
    public void register(TbUser user) {
        userMapper.insertSelective(user);
    }

    @Override
    public TbUser getInfoToLogin(String username) {
        TbUserExample example = new TbUserExample();
        TbUserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<TbUser> list = userMapper.selectByExample(example);
        if(list != null && list.size() > 0) {
            return list.get(0);
        }
        return null;
    }
}
